00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00034 class MessagingAutoSearch {
00035
00041 private $searchString;
00042
00048 private $db;
00049
00055 private $messaging;
00056
00061 private $translate;
00062
00067 private $locale;
00068
00075 public function __construct($searchString, $messaging) {
00076 global $db;
00077 $this->db = $db;
00078 $this->messaging = $messaging;
00079 $this->searchString = Data::toMysql(trim($searchString));
00080
00081 $this->locale = getLocale();
00082 $this->translate = getTranslate("messaging");
00083 }
00084
00090 public function getSearchResults() {
00091
00092 $queryOk = false;
00093 $autolist = "";
00094 $whereAddition = "";
00095 $searchQuery = "SELECT DISTINCT(user.ID),
00096 user.Nachname,
00097 user.Vorname,
00098 user.ShortName,
00099 user.picture
00100 FROM user";
00101
00102 $commaCount = substr_count ($this->searchString, "," );
00103
00104 if ($commaCount <= 0) {
00105
00106 $whereAddition = "AND user.Nachname LIKE '" . $this->searchString . "%'";
00107 } else {
00108
00109
00110 $comma = strpos($this->searchString, ",");
00111
00112
00113 $aftername = substr($this->searchString, 0, $comma);
00114 $prename = substr($this->searchString, $comma+1, (strlen($this->searchString)-$comma));
00115
00116 $whereAddition = "AND user.Nachname LIKE '".$aftername."%' AND user.Vorname LIKE '".$prename."%'";
00117 }
00118
00119 $searchQuery.= " WHERE user.Invisible = '0' ".$whereAddition." ORDER BY user.Nachname, user.Vorname";
00120
00121 if($this->searchString != "") {
00122 global $memcache;
00123
00124 $md5hashOfSearchString = "messaging_autocompletion_". md5($this->searchString);
00125
00126 if ($memcache instanceof Memcache) {
00127
00128 $queryResults = $memcache->get($md5hashOfSearchString);
00129
00130 if($queryResults == false) {
00131
00132 $queryResults = $this->db->get_results($searchQuery);
00133 if($this->db->num_rows > 0) {
00134 $memcache->set($md5hashOfSearchString, $queryResults, false, 3600);
00135 $queryOk = true;
00136 }
00137 else {
00138 $queryOk = false;
00139 }
00140
00141 }
00142 else {
00143 $queryOk = true;
00144 }
00145 }
00146 else {
00147
00148 $queryResults = $this->db->get_results ($searchQuery);
00149 if($this->db->num_rows > 0) {
00150 $queryOk = true;
00151 }
00152 else {
00153 $queryOk = false;
00154 }
00155 }
00156 }
00157
00158 if($queryOk) {
00159 global $settings;
00160 foreach($queryResults as $searchHit) {
00161 $userPicture = "";
00162
00163 $userPicture = PATH_TO_ROOT.$settings["upload_path"]."user/".$searchHit->ID."/".$searchHit->picture;
00164
00165
00166 if(!is_file($userPicture)) {
00167 $avatar = $this->db->get_row("SELECT useravatar FROM forum_user WHERE userID='$searchHit->ID'");
00168 $avatar = $avatar->useravatar;
00169 if(empty($avatar) || $avatar == "userpicture") {
00170 $userPicture = "../images/nopic.gif";
00171 }
00172 else {
00173 $userPicture = PATH_TO_ROOT."forum/".$avatar;
00174 }
00175 }
00176
00177
00178 $countUsers = $this->messaging->sameNameUsers($searchHit->ID);
00179 $jsName = "";
00180 if($countUsers > 0) {
00181 $jsName = $searchHit->Nachname.", ".$searchHit->Vorname.", ".$searchHit->ShortName;
00182 }
00183 else {
00184 $jsName = $searchHit->Nachname.", ".$searchHit->Vorname;
00185 }
00186
00187 $autolist .= "<a href=\"#\" class=\"messaging_autosearch\" onclick=\"hideAutoList('messaging_autocompletion_div'); addUserToRecipients('".$jsName."');\" title=\"".$this->translate->_("Zu Empfaenger hinzufuegen")."\">
00188 <img src=\"".PATH_TO_ROOT."common/makethumb.php?picurl=".$userPicture."&maxw=30&maxh=30\" alt=\"pic\" ".$searchHit->Nachname."\" title=\"".$this->translate->_("Zu Empfaenger hinzufuegen")."\" />
00189 ".$searchHit->Vorname." ".$searchHit->Nachname."</a>";
00190 }
00191 }
00192 else {
00193 $autolist .= "<p>".$this->translate->_("Keinen Benutzer gefunden!")."</p>";
00194 }
00195
00196 return $autolist;
00197 }
00198 }
00199 ?>